﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using MotoGame.Estados;
using MotoGame;
using MotoGame.Jogos.Estados.Fases.Moto;
using Trunk.Jogo.Core;

namespace Trunk.Jogo.Estados.Fases
{
    /// <summary>
    /// Gerencia o parallax das fases
    /// </summary>
    class ParallaxLayer: Microsoft.Xna.Framework.Game
    {   public Texture2D textura;
        private Vector2 posicao;
        private Vector2 velocidade;
        
        public Vector2 Posicao 
        {
            get { return this.posicao; }
            set { this.posicao = value; }
        }

        public ParallaxLayer(float velX, float velY)
        {
            this.posicao = new Vector2(0, 0);
            this.velocidade = new Vector2(velX, velY);
        }

        public void LoadContent(ContentManager content, string filename)
        {
            this.textura = content.Load<Texture2D>(filename);
        }

        public void Update(GameTime gameTime, Vector2 velocidadeParalax)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            this.posicao.X -= velocidadeParalax.X * this.velocidade.X * deltaTime;
            this.posicao.X = this.posicao.X % this.textura.Width;
        }

        public void Draw(SpriteBatch batch)
        {
            batch.Draw(this.textura, this.posicao, Color.White);
            batch.Draw(this.textura, new Vector2(this.posicao.X + this.textura.Width, 0), Color.White);
        }
    }
}

